package com.hjh.smbmsthymeleaf.service.Impl;

import com.hjh.smbmsthymeleaf.entity.Provider;
import com.hjh.smbmsthymeleaf.mapper.ProviderMapper;
import com.hjh.smbmsthymeleaf.service.ProviderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProviderServiceImpl implements ProviderService {

    @Resource
    private ProviderMapper providerMapper;

    @Transactional
    @Override
    public boolean insertProvider(Provider provider) {
        boolean flag = false;
        if(providerMapper.insert(provider) > 0){
            flag = true;
        }
        return flag;
    }

    @Transactional
    @Override
    public boolean deleteProvider(Long id) {
        boolean flag = false;
        if(providerMapper.deleteById(id) > 0){
            flag = true;
        }
        return flag;
    }

    @Transactional
    @Override
    public int updateProvider(Provider provider) {
        return providerMapper.updateById(provider);
    }

    @Override
    public Provider getProviderById(Long id) {
        return providerMapper.selectById(id);
    }

    @Override
    public List<Provider> findAllProviders() {
        return providerMapper.selectList(null);
    }
}
